package com.zhy.user.controller;

import com.zhy.redis.util.RedisShareLockUtil;
import com.zhy.tool.util.ExportWordUtil;
import com.zhy.user.entity.po.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * @author 随缘而愈
 * @version 1.0
 * @description TODO
 * @date 26/1/2024 上午11:51
 */
@RestController
@Slf4j
public class TestController {
    @Resource
    private RedisTemplate redisTemplate;
    @Resource
    private RedisShareLockUtil redisShareLockUtil;

    @GetMapping("/testRedis")
    public void testRedis() {
        redisTemplate.opsForValue().set("name","Yuan");
    }

    @GetMapping("/testRedisLock")
    public void testRedisLock() {
        redisShareLockUtil.lock("lockKey","Yuan",100000L);
    }

    @GetMapping("/testLog")
    public void testLog() {
        long startTime = System.currentTimeMillis();
        for (int i = 0;i < 10000;i++){
            log.info("这是第{}条日志",i);
        }
        long endTime = System.currentTimeMillis();
        log.info("耗时{}", endTime - startTime);
    }

    @GetMapping("/testWord")
    public void testWord() throws Exception {
        HashMap<String, Object> mapData = new HashMap<>();
        mapData.put("name","随缘");
        mapData.put("auditName","而愈");
        ExportWordUtil.exportWord(mapData,"导出文件","wordExport.ftl");
    }

    @GetMapping("/testQuery")
    public void testQuery(@RequestBody SysUser sysUser) throws Exception {
        System.out.println(sysUser);
    }
}
